//index.js
//获取应用实例
const app = getApp()
const getdata = require("../../tool/GetDate.js");

Page({
  data: {
    bcList: [],
    msgList: [
      // {
      //   url: "url",
      //   title: "公告：多地首套房贷利率上浮 热点城市渐迎零折扣时代"
      // },
      // {
      //   url: "url",
      //   title: "公告：悦如公寓三周年生日趴邀你免费吃喝欢唱"
      // },
      // {
      //   url: "url",
      //   title: "公告：你想和一群有志青年一起过生日嘛？"
      // }
    ],
  },

  onLoad: function() {
    if (!app.globalData.myUserData.userID) {
      wx.reLaunch({
        url: '/pages/user_registration/user_registration',
      })
    }
  },

  onShow: function() {
    let that = this;
    try {
      let param = {};
      param.userID = app.globalData.myUserData.userID;
      param.districtID = app.globalData.myUserData.districtID;
      console.log(param);
      
      getdata.postdata({
        url: "gbt/Meal/MealReport",
        data: JSON.stringify(param),
        success: function(res) {
          console.log(res.root);
          if (res.root) {
            let mealData = res.root.data;
            let mealItem = {};
            let bcList = [];
            for (let mealIndex = 0; mealIndex < mealData.length; mealIndex++) {
              mealItem.title = mealData[mealIndex].name;
              mealItem.hallName = mealData[mealIndex].hallName;
              mealItem.mealDateTitle = "报餐日期";
              mealItem.mealDateValue = mealData[mealIndex].date.replace("T00:00:00","");
              mealItem.mealTitle = "餐点";
              mealItem.mealValue = mealData[mealIndex].mealName;
              mealItem.numTitle = "份数";
              mealItem.numValue = mealData[mealIndex].qty;
              mealItem.amount = mealData[mealIndex].amount;
              mealItem.currency = "元";
              bcList.push(mealItem);
              mealItem = {};
            }

            that.setData({
              bcList: bcList,
            });
          }
        }
      });
    } catch {}
  },

  onAllSalesman: function() {
    //跳转到个人报餐查询页面
    wx.navigateTo({
      url: '/pages/meal_my_all/meal_my_all',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})